<template>
	<div id="">
		<el-form :inline="true" size="medium">
            <el-form-item>
				<el-select v-model="params.tenantId" placeholder="分站" @change="search" filterable>
					<el-option v-for="item in tenantList" :value="item.id" :label="item.company"></el-option>
				</el-select>
            </el-form-item>
            <el-form-item>
				<el-date-picker
					@change = 'timeChange'
					v-model="timeArr"
					type="datetimerange"
					range-separator="至"
					start-placeholder="开始日期"
					end-placeholder="结束日期">
				</el-date-picker>
			</el-form-item>
            <el-form-item>
				<el-button type="primary" @click="search">搜索</el-button>
                <span> 从2021-07-07开始统计</span>
			</el-form-item>
		</el-form>

		<el-table :data="list" stripe v-loading="loading">
            <el-table-column align="center" label="分站">
                <template slot-scope="scope">
                    <span v-for="item in tenantList" v-if="item.id == scope.row.tenant_id">{{item.company}}</span>
                </template>
            </el-table-column>
            <el-table-column align="center" label="商家注册量" prop="bus_num"></el-table-column>
            <el-table-column align="center" label="充值金额" prop="recharge"></el-table-column>
            <el-table-column align="center" label="订单数" prop="order_num"></el-table-column>
            <el-table-column align="center" label="包裹数" prop="pk_num"></el-table-column>
            <el-table-column align="center" label="平台收益" prop="profit"></el-table-column>
            <el-table-column align="center" label="分站收益" prop="tenant_profit"></el-table-column>
            <el-table-column align="center" label="创建时间">
                <template slot-scope="scope">
                    {{$common.getDate(scope.row.create_time)}}
                </template>
            </el-table-column>
        </el-table>

		<el-pagination 
			class="page"
			background
			@size-change="handleSizeChange" 
			@current-change="getList" 
			:current-page.sync="params.pageNo" 
			:page-sizes="[10, 20, 50, 100]" 
			:page-size="params.pageSize" 
			layout="total, sizes, prev, pager, next, jumper" 
			:total="total">
		</el-pagination>

	</div>
</template>

<script>
	export default {
		data() {
			return {
                params: {
                    startTime: '',
                    endTime: '',
                    tenantId: 1,
                    pageNo: 1,
                    pageSize: 10
                },
                timeArr: [],
                tenantList:[],
                list: [],
                loading: false,
                total: 100
            }
		},
		watch: {},

		created() {
            this.getTenantList()
            this.search()
		},

		mounted() {
		},

		methods: {
            search(){
                this.getList();
                this.getCount();
            },
            timeChange(val){
                if(val){
                    this.params.startTime = this.$common.getDate(val[0]);
                    this.params.endTime = this.$common.getDate(val[1]);
                }else{
                    this.params.startTime = ''
                    this.params.endTime = ''
                }
            },
            handleSizeChange(e){
                this.params.pageSize = e
                this.getList();
            },
            getList(){
                this.$request.post({
                    url: '/ReportApi/admin/everdaylist',
                    params: this.params,
                    success: res => {
                        this.list = res;
                    },
                    finally: res => {
                        this.loading = false
                    }
                })
            },
            getCount(){
                this.$request.post({
                    url: '/ReportApi/admin/everdaycount',
                    params: this.params,
                    success: res => {
                        this.total = res;
                    },
                    finally: res => {
                        this.loading = false
                    }
                })
            },
            getTenantList(){
                this.$request.post({
                    url:'/ReportApi/admin/everdayalllist',
                    success: res => {
                        this.tenantList = res;
                        this.tenantList.unshift({
							id:0,
							company:'全部',
						})
                    }
                })
            },
		},

		beforeDestroy() {}
	}
</script>

<style lang="scss">
</style>

<style lang="scss" scoped>
	.page{
		text-align: right;
		margin-top: 20px;
	}
</style>
